package com.cy6;

import java.io.*;

public class CopyFolderDemo {
    public static void main(String[] args) throws IOException {
        File srcFolder = new File("D:\\itcast");
        String srcFolderName = srcFolder.getName();
        File destFolder = new File("myCharStream", srcFolderName);
        if(!destFolder.exists()){
            destFolder.mkdir();
        }
        File[] files = srcFolder.listFiles();
        for (File file : files) {
            String fileName = file.getName();
            File file1 = new File(destFolder,fileName);
            copy(file,file1);
        }

    }

    private static void copy(File file, File file1) throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file1));
        int len;
        byte[] bytes = new byte[1024];
        while((len=bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
        }
        bis.close();
        bos.close();
    }
}
